package com.xhh.nphm.system.mapper;

import com.baomidou.mybatisplus.annotation.SqlParser;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xhh.nphm.common.core.domain.QueryConditionVo;
import com.xhh.nphm.system.domain.*;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.StatementType;
import org.harmony.toddler.mybatis.groovy.GroovyLangDriver;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository
public interface WfSendBackDao extends BaseMapper<TwfSendBackEty> {

    @Select("select * from tWfSendBack where WfId=#{wfId} and isDel=0")
    List<TwfSendBackEty> selectByWfIdList(Integer wfId);

    @Select("select * from tWfSendBack where GetDealPk=#{id}")
    TwfSendBackEty selectByGetDealPk(Integer id);

    @Select("select * from tWfSendBack where PkId=#{sid}")
    TwfSendBackEty selectByPkId(Integer sid);

    /**
     * 调整承办部门 列表数据
     *
     * @return
     */
    @Select("select pkId ,wfId,seqName,sortName,dealName,sbdeptName,sendDesc,sdeptName,convert(varchar(19),BackLimit,20) as backLimit,suserName,convert(varchar(19),sendTime,20) as sendTime,sendState,convert(varchar(19),GetTime,20) as getTime,getPerson,buserName,convert(varchar(19),BackTime,20) as backTime,PkId as myOP from tWfSendBack where WfId=#{wfId} and OriLevel=1 and IsDel=0 " +
            "[[and sbdeptName=#{sbdeptName}]]" +
            "[[and sortName=#{sortName}]]" +
            " order by PkId desc")
    List<TwfSendBackEty> sendBackListJson(TwfSendBackEty twfSendBackEty);

    /**
     * 下级退回电话工单审核 列表
     *
     * @param twfSendBackEty
     * @return
     */
    @Select("select PkId,WfId,GetDealPK,(select WorkFormNO from tWorkFormBase where PkId=WfId) as myTwfNO,(select WsTopic from tWorkFormBase where PkId=WfId) as myTwfTopic,SeqName,SBDeptName,SortName,DealName,convert(varchar(10),BackLimit,20) bkLimit,SDeptName,convert(varchar(10),SendTime,20) sdDate,convert(varchar(10),GetTime,20) as bkDate,BackRemark from tWfSendBack where  SendState=40 and BackState=11 and flagInt=1 and IsDel=0 [[and SDeptID=#{deptNo}]] ")
    @SqlParser(filter = true)
    List<TwfSendBackEty> treturnFlowJson(TwfSendBackEty twfSendBackEty, @Param("deptNo") String deptNo);

    /**
     * 根据 wfid 查询单个 派单记录
     *
     * @param wfId
     * @return
     */
    @Select("select * from tWfSendBack where WfId= #{wfId}")
    TwfSendBackEty getByWfId(@Param("wfId") Integer wfId);

    @Update("update tWfSendBack set SendRemark=#{sendRemark},BackState=#{backState},FlagInt=0 where PkId=#{pkId}")
    int updateTwfSendBack(@Param("sendRemark") String sendRemark, @Param("backState") Integer backState, @Param("pkId") Integer pkId);

    @Update("<script>" +
            "UPDATE tWfSendBack SET IsDel=1 WHERE PkId IN " +
            "<foreach collection='array' item='id' open='(' separator=',' close=')'>#{id}</foreach>"
            + "</script>")
    int deleteByIds(String[] ids);

    /**
     * 查找待本部门回复的工单数据
     *
     * @param deptId 部门id
     * @return 工单列表数据
     */
    @Select("select t1.PkId as myPkVal,WfId,OriLevel,SDeptID as fmDept,SBDeptID as sbDept,isUrge," +
            "t2.WorkFormNO as myTwfNO,t2.WsTopic as myTwfTopic,t2.fmContent as FmContent," +
            " (select SortName from bSort where CodePk=str(left(t3.DCntACode,4),4)) dCntAName1, " +
            " (select SortName from bSort where CodePk=str(left(t3.DCntACode,6),6)) dCntAName2, " +
            " (select SortName from bSort where CodePk=str(left(t3.DCntACode,8),8)) dCntAName3, " +
            "SeqName,SBDeptName,SortName,DealName,convert(varchar(10),BackLimit,20) as bkLimit,SDeptName,convert(varchar(10),GetTime,20) as acDate," +
            "BackState as bkState,BackRemark as acRemark,t1.PkId as opDeal,BackDesc as backDesc," +
            "subBackState cbackDesc " +
//            "dbo.tWfNOBackDesc(WfId,#{sbdeptId}) cbackDesc " +
            " from tWfSendBack t1 left join tWorkFormBase t2 on t1.WfId=t2.PkId left join tTelGetDeal t3 on t1.GetDealPk = t3.PkId " +
            "where t1.SBDeptID=#{sbdeptId} and t1.SendState in(21,23) and t1.BackState in (0,12,22) and t1.IsDel=0 and t2.IsDel=0 " +
            "[[and t2.WorkFormNO = #{qc.workFormNO}]] " +
            "[[and t1.subBackState=#{qc.backDesc}]] " +
//            "[[and #{qc.backDesc} = dbo.tWfNOBackDesc(WfId,#{sbdeptId})]] " +
            "[[and convert(varchar(10),t1.BackLimit,120) &gt;= #{qc.beginTime}]] [[and convert(varchar(10),t1.BackLimit,120) &lt;= #{qc.endTime}]] " +
            "[[and t1.SDeptName =#{qc.sdeptName}]]")
    List<Map<String, Object>> muReplyWaitJson(@Param("sbdeptId") String deptId, @Param("qc") QueryConditionVo qc);

    @Select("select t1.PkId as myPkVal,WfId,OriLevel,SDeptID as fmDept,SBDeptID as sbDept,isUrge," +
            "t2.WorkFormNO as myTwfNO,t2.WsTopic as myTwfTopic,t2.fmContent as FmContent," +
            " (select SortName from bSort where CodePk=str(left(t3.DCntACode,4),4)) dCntAName1, " +
            " (select SortName from bSort where CodePk=str(left(t3.DCntACode,6),6)) dCntAName2, " +
            " (select SortName from bSort where CodePk=str(left(t3.DCntACode,8),8)) dCntAName3, " +
            "SeqName,SBDeptName,SortName,DealName,convert(varchar(10),BackLimit,20) as bkLimit,SDeptName,convert(varchar(10),GetTime,20) as acDate," +
            "BackState as bkState,BackRemark as acRemark,PkId as opDeal,BackDesc as backDesc," +
//            "subBackState cbackDesc " +
            "dbo.tWfNOBackDesc(WfId,#{sbdeptId}) cbackDesc " +
            " from tWfSendBack t1 left join tWorkFormBase t2 on t1.WfId=t2.PkId left join tTelGetDeal t3 on t1.GetDealPk = t3.PkId " +
            "where t1.SBDeptID=#{sbdeptId} and t1.SendState in(21,23) and t1.BackState in (0,12,22) and t1.IsDel=0 and t2.IsDel=0 and t1.isUrge = 1 " +
            "[[and t2.WorkFormNO = #{qc.workFormNO}]]" +
//            "[[and t1.subBackState=#{qc.backDesc}]] " +
            "[[and #{qc.backDesc} = dbo.tWfNOBackDesc(WfId,#{sbdeptId})]] " +
            "[[and convert(varchar(10),t1.BackLimit,120) &gt;= #{qc.beginTime}]] [[and convert(varchar(10),t1.BackLimit,120) &lt;= #{qc.endTime}]] " +
            "[[and t1.SDeptName =#{qc.sdeptName}]]")
    List<Map<String, Object>> muReplyWaitJson1(@Param("sbdeptId") String deptId,@Param("qc") QueryConditionVo qc);

    /**
     * 查找待本部门回复的工单数据
     *
     * @param paramMap 参数
     * @return 工单列表数据
     */
    @Select("WfSendBackSql#muReplyWaitJson_jjq")
    @Lang(GroovyLangDriver.class)
    List<Map<String, Object>> muReplyWaitJson_jjq(Map paramMap);

    @Select("WfSendBackSql#muReplyWaitJson_px")
    @Lang(GroovyLangDriver.class)
    List<Map<String, Object>> muReplyWaitJson_px(Map paramMap);

    /**
     * 查找待本部门回复的工单数据导出
     *
     * @param paramMap 参数
     * @return 工单列表数据
     */
    @Select("DataExportSql#muReplyWaitJson_jjqExport")
    @Lang(GroovyLangDriver.class)
    List<MuReplyWaitTelExcel> muReplyWaitJson_jjqExport(Map paramMap);

    @Select("DataExportSql#muReplyWaitJson_pxExport")
    @Lang(GroovyLangDriver.class)
    List<MuReplyWaitTelExcel> muReplyWaitJson_pxExport(Map paramMap);

    @Select("DataExportSql#muReplyWaitJson_gxqExport")
    @Lang(GroovyLangDriver.class)
    List<MuReplyWaitTelExcel> muReplyWaitJson_gxqExport(Map paramMap);

    /**
     * 市级未签收列表数据
     *
     * @param twfSendBackEty
     * @param deptId
     * @return
     */
    @Select("SELECT t1.PkId,t1.WfId,t2.WorkFormNO AS myTwfNO,t2.WsTopic AS myTwfTopic,t2.FmContent,SeqName," +
            " SBDeptName,SortName,DealName,CONVERT(VARCHAR(10),BackLimit,20) bkLimit,SDeptName," +
            " CONVERT(VARCHAR(10),SendTime,20) sdDate,SendRemark,SAttachPath,Mark FROM" +
            " tWfSendBack t1 inner join tWorkFormBase t2 on t1.WfId=t2.PkId" +
            " WHERE t1.IsDel=0 AND t2.IsDel=0 AND SBDeptID=#{deptId} AND SendState IN(10,11)" +
            " AND dbo.frTelWFStep (WfId)>399 [[and WorkFormNO=#{twf.myTwfNO}]][[and SBDeptName=#{twf.sbdeptName}]]")
    List<TwfSendBackEty> muSignNotJson(@Param("twf") TwfSendBackEty twfSendBackEty, @Param("deptId") String deptId);

    @Select("SELECT t1.PkId,t1.WfId,t2.WorkFormNO AS myTwfNO,t2.WsTopic AS myTwfTopic,t2.FmContent,SeqName," +
            " SBDeptName,SortName,DealName,CONVERT(VARCHAR(10),BackLimit,20) bkLimit,SDeptName," +
            " CONVERT(VARCHAR(10),SendTime,20) sdDate,SendRemark,SAttachPath,Mark FROM" +
            " tWfSendBack t1 inner join tWorkFormBase t2 on t1.WfId=t2.PkId" +
            " WHERE t1.IsDel=0 AND t2.IsDel=0 AND SBDeptID=#{deptId} AND SendState IN(10,11)" +
            " AND dbo.frTelWFStep (WfId)>399 AND dbo.frTelWFStep (WfId)&lt;900 and DATEDIFF(day, GETDATE(), t1.BackLimit) > -30 and t1.BackTime is null [[and WorkFormNO=#{twf.myTwfNO}]][[and SBDeptName=#{twf.sbdeptName}]]")
    List<TwfSendBackEty> muSignNotJson_gxq(@Param("twf") TwfSendBackEty twfSendBackEty, @Param("deptId") String deptId);

    /**
     * 查找审核本级回复的工单数据
     *
     * @param deptId     部门id
     * @param workFormNo
     * @param sdeptName
     * @return 工单列表数据
     */
    @Select("select PkId as myPkVal,WfId,OriLevel,SDeptID as fmDept,SBDeptID as sbDept," +
            "(select WorkFormNO from tWorkFormBase where PkId=WfId) as myTwfNO,(select WsTopic from tWorkFormBase where PkId=WfId) as myTwfTopic," +
            "SeqName,SortName,DealName,SDeptName,convert(varchar(10),BackLimit,20) as bkLimit,SBDeptName,convert(varchar(10),BackTime,20) as bkDate," +
            "BackState as chgBack,PkId as opDeal from tWfSendBack " +
            "where SBDeptID=#{sbdeptId} and BackState=10 and IsDel=0 " +
            "[[and (select WorkFormNO from tWorkFormBase where PkId=WfId) = #{workFormNo}]] [[and SDeptName =#{sdeptName}]]")
    List<Map<String, Object>> muReplyChkJson(@Param("sbdeptId") Long deptId, @Param("workFormNo") String workFormNo, @Param("sdeptName") String sdeptName);

    /**
     * 查找本部门已办毕的工单数据
     *
     * @param deptId     部门id
     * @param workFormNo 工单编号
     * @param sdeptName  派发单位
     * @return 工单列表数据
     */
    @Select("select PkId as myPkVal,WfId,GetDealPK as telId," +
            "(select WorkFormNO from tWorkFormBase where PkId=WfId) as myTwfNO," +
            "(select WsTopic from tWorkFormBase where PkId=WfId) as myTwfTopic," +
            "(select fmContent from tWorkFormBase where PkId=WfId) as FmContent," +
            "SDeptName,SeqName,SBDeptName,SortName,DealName,convert(varchar(10),BackLimit,20) as bkLimit," +
            "convert(varchar(10),BackTime,20) as bkDate,BackState as chgBack,SendState,BackState,BackRemark from tWfSendBack " +
            "where SBDeptID=#{sbdeptId} and BackState in (11,21) and IsDel=0 " +
//            "where SBDeptID=#{sbdeptId} and BackState in (11,21) and IsDel=0 and SendState not in(30,40)" +
            "[[and (select WorkFormNO from tWorkFormBase where PkId=WfId) = #{workFormNo}]] [[and SDeptName =#{sdeptName}]] ")
    List<Map<String, Object>> muReplyOverJson(@Param("sbdeptId") String deptId, @Param("workFormNo") String workFormNo, @Param("sdeptName") String sdeptName);

    /**
     * 查找本部门退回的工单数据
     *
     * @param deptId     部门id
     * @param workFormNo 工单编号
     * @param sdeptName  派发单位
     * @return 工单列表数据
     */
    @Select("select PkId as myPkVal,WfId,GetDealPK as telId," +
            "(select WorkFormNO from tWorkFormBase where PkId=WfId) as myTwfNO," +
            "(select WsTopic from tWorkFormBase where PkId=WfId) as myTwfTopic," +
            "SeqName,SBDeptName,SortName,DealName,convert(varchar(10),BackLimit,20) bkLimit," +
            "SDeptName,convert(varchar(10),SendTime,20) sdDate,convert(varchar(10),GetTime,20) as bkDate,backState," +
            "BackRemark,PkId as opDeal from tWfSendBack where SBDeptID=convert(varchar,#{sbdeptId}) and SendState=40 and IsDel=0 " +
            "[[and (select WorkFormNO from tWorkFormBase where PkId=WfId) = #{workFormNo}]] [[and SDeptName =#{sdeptName}]]")
    List<Map<String, Object>> muDeptBackJson(@Param("sbdeptId") Long deptId, @Param("workFormNo") String workFormNo, @Param("sdeptName") String sdeptName);

    /**
     * 根据 wfid 和 sdeptId 查询派单记录列表
     *
     * @param wfId    工单id
     * @param sdeptId 派发单位Id
     * @return 派单记录列表
     */
    @Select("select * from tWfSendBack where WfId= #{wfId} AND SDeptId = #{sdeptId} AND sortCode <> '21' AND sendState <> 40 AND isDel=0")
    List<TwfSendBackEty> ltSendBackMain(@Param("wfId") Integer wfId, @Param("sdeptId") String sdeptId);

    /**
     * 查找待分发下级工单数据
     *
     * @param deptId     部门id
     * @param workFormNo 工单编号
     * @param sdeptName  派发单位
     * @return 工单列表数据
     */
    @Select("select PkId as myPkVal,getDealPk,WfId,(select WorkFormNO from tWorkFormBase where PkId=WfId) as myTwfNO," +
            "(select WsTopic from tWorkFormBase where PkId=WfId) as myTwfTopic,SeqName,SBDeptName,SortName,SDeptName," +
            "convert(varchar(10),BackLimit,20) BackLimit,convert(varchar(10),GetTime,20) as acDate,BackRemark as acDesc from tWfSendBack" +
            " where SBDeptID=#{sbdeptId} and SendState=22 and IsDel=0 " +
            "[[and (select WorkFormNO from tWorkFormBase where PkId=WfId) = #{workFormNo}]] [[and SDeptName =#{sdeptName}]]")
    List<Map<String, Object>> sendWaitListJson(@Param("sbdeptId") Long deptId, @Param("workFormNo") String workFormNo, @Param("sdeptName") String sdeptName);

    @Select("select PkId as myPkVal,getDealPk,WfId,(select WorkFormNO from tWorkFormBase where PkId=WfId) as myTwfNO," +
            "(select WsTopic from tWorkFormBase where PkId=WfId) as myTwfTopic,SeqName,SBDeptName,SortName,SDeptName," +
            "convert(varchar(10),BackLimit,20) BackLimit,convert(varchar(10),GetTime,20) as acDate,BackRemark as acDesc from tWfSendBack " +
            " where SBDeptID=#{sbdeptId} and SendState=22 and IsDel=0 and dbo.frTelWFStep(WfId) > 399 and dbo.frTelWFStep(WfId) &lt; 900 and DATEDIFF(day,GetDate(),BackLimit) > -60 " +
            "[[and (select WorkFormNO from tWorkFormBase where PkId=WfId) = #{workFormNo}]] [[and SDeptName =#{sdeptName}]]")
    List<Map<String, Object>> sendWaitListJson_gxq(@Param("sbdeptId") Long deptId, @Param("workFormNo") String workFormNo, @Param("sdeptName") String sdeptName);

    /**
     * 查找上级不同意退回工单数据
     *
     * @param deptId     部门编号
     * @param workFormNo 工单编号
     * @param sdeptName  派发单位
     * @return 列表数据
     */
    @Select("select PkId as myPkVal,WfId,(select WorkFormNO from tWorkFormBase where PkId=WfId) as myTwfNO," +
            "(select WsTopic from tWorkFormBase where PkId=WfId) as myTwfTopic,SeqName,SBDeptName,SortName,DealName," +
            "convert(varchar(10),BackLimit,20) bkLimit,SDeptName,convert(varchar(10),SendTime,20) sdDate,SendRemark,SAttachPath" +
            " from tWfSendBack where SBDeptID=#{sbdeptId} and SendState=51 and dbo.frTelWFStep(WfId)>399 and IsDel=0 " +
            "[[and (select WorkFormNO from tWorkFormBase where PkId=WfId) = #{workFormNo}]] [[and SDeptName =#{sdeptName}]]")
    List<Map<String, Object>> notPassListJson(@Param("sbdeptId") Long deptId, @Param("workFormNo") String workFormNo, @Param("sdeptName") String sdeptName);

    /**
     * 查找下级退回工单数据
     *
     * @param deptId     部门编号
     * @param workFormNo
     * @param sdeptName  派发单位
     * @return 列表数据
     */
    @Select("select PkId as myPkVal,WfId as twfpk,GetDealPK as telpk,SDeptID as fDNo," +
            "(select WorkFormNO from tWorkFormBase where PkId=WfId) as WfId,(select WsTopic from tWorkFormBase where PkId=WfId) as myTwfTopic," +
            "SBDeptName,SeqName,SortName,convert(varchar(10),BackLimit,20) BackLimit,SendRemark,SendState,BackState,BackState as chgChk,SAttachPath from tWfSendBack" +
            " where SDeptID=#{sdeptId} and SendState=40 and IsDel=0 " +
            "[[and (select WorkFormNO from tWorkFormBase where PkId=WfId) = #{workFormNo}]] [[and SDeptName =#{sdeptName}]]")
    List<Map<String, Object>> listSonBackJson(@Param("sdeptId") Long deptId, @Param("workFormNo") String workFormNo, @Param("sdeptName") String sdeptName);

    /**
     * 查找承办单位已退工单数据
     *
     * @param params 查询条件
     * @return 列表数据
     */
    @Select("select PkId as myPkVal,WfId as twfpk,GetDealPK as telpk,SDeptID as fDNo," +
            "(select WorkFormNO from tWorkFormBase where PkId=WfId) as WfId,(select WsTopic from tWorkFormBase where PkId=WfId) as myTwfTopic," +
            "SBDeptName,SeqName,SortName,convert(varchar(10),BackLimit,20) BackLimit,SendRemark,SendState,BackState,BackState as chgChk,SAttachPath from tWfSendBack" +
            " where  SDeptID=#{sdeptId} and SendState=40 and BackState=21 and IsDel=0 " +
            "[[and (select WorkFormNO from tWorkFormBase where PkId=WfId) = #{sendBack.myTwfNO}]] [[and SDeptName =#{sendBack.sdeptName}]]")
    List<Map<String, Object>> listSonAgreeBackJson(HashMap<String, Object> params);

    @Select("select PkId as myPkVal,WfId as twfpk,GetDealPK as telpk,SDeptID as fDNo," +
            "(select WorkFormNO from tWorkFormBase where PkId=WfId) as WfId,(select WsTopic from tWorkFormBase where PkId=WfId) as myTwfTopic," +
            "SBDeptName,SeqName,SortName,convert(varchar(10),BackLimit,20) BackLimit,SendRemark,SendState,BackState,BackState as chgChk,SAttachPath from tWfSendBack" +
            " where  SDeptID=#{sdeptId} and SendState=40 and BackState=21 and IsDel=0 and DATEDIFF(day, GETDATE(), BackLimit) > -30 " +
            "[[and (select WorkFormNO from tWorkFormBase where PkId=WfId) = #{sendBack.myTwfNO}]] [[and SDeptName =#{sendBack.sdeptName}]]")
    List<Map<String, Object>> listSonAgreeBackJson_gxq(HashMap<String, Object> params);

    /**
     * 查找承办单位未签收工单数据
     *
     * @param params 查询条件
     * @return 列表数据
     */
    @Select("select PkId,WfId,(select WorkFormNO from tWorkFormBase where PkId=WfId) as myTwfNO,  " +
            "(select WsTopic from tWorkFormBase where PkId=WfId) as myTwfTopic,SeqName,SBDeptName,SortName,  " +
            "DealName,convert(varchar(10),BackLimit,20) bkLimit,SDeptName,convert(varchar(10),SendTime,20) sdDate,  " +
            "SendRemark,PkId as opDeal,SAttachPath,(select mark from tWorkFormBase where PkId=WfId) as Mark  " +
            "from tWfSendBack where  SDeptID=#{sdeptId} and SendState in (10,11) and dbo.frTelWFStep(WfId)>399 and IsDel=0 " +
            "[[and (select WorkFormNO from tWorkFormBase where PkId=WfId) = #{sendBack.myTwfNO}]][[and SBDeptName=#{sendBack.sdeptName}]]")
    List<Map<String, Object>> listSonSignNot(HashMap<String, Object> params);

    @Select("select PkId,WfId,(select WorkFormNO from tWorkFormBase where PkId=WfId) as myTwfNO,  " +
            "(select WsTopic from tWorkFormBase where PkId=WfId) as myTwfTopic,SeqName,SBDeptName,SortName,  " +
            "DealName,convert(varchar(10),BackLimit,20) bkLimit,SDeptName,convert(varchar(10),SendTime,20) sdDate,  " +
            "SendRemark,PkId as opDeal,SAttachPath,(select mark from tWorkFormBase where PkId=WfId) as Mark  " +
            "from tWfSendBack where  SDeptID=#{sdeptId} and SendState in (10,11) and dbo.frTelWFStep(WfId)>399 and IsDel=0 and DATEDIFF(day, GETDATE(), BackLimit) > -30 " +
            "[[and (select WorkFormNO from tWorkFormBase where PkId=WfId) = #{sendBack.myTwfNO}]][[and SBDeptName=#{sendBack.sdeptName}]]")
    List<Map<String, Object>> listSonSignNot_gxq(HashMap<String, Object> params);

    /**
     * 查找临期工单数据(差两天 超出办理期限工单)
     *
     * @param params 查询条件
     * @return 列表数据
     */
    @Select("select PkId as myPkVal,WfId,OriLevel,SDeptID as fmDept,SBDeptID as sbDept," +
            "(select WorkFormNO from tWorkFormBase where PkId=WfId) as myTwfNO,(select WsTopic from tWorkFormBase where PkId=WfId) as myTwfTopic," +
            "SeqName,SBDeptName,SortName,DealName,convert(varchar(10),BackLimit,20) as bkLimit,SDeptName,convert(varchar(10),GetTime,20) as acDate," +
            "BackState as bkState,BackRemark as acRemark,PkId as opDeal,BackDesc as backDesc from tWfSendBack " +
            "where  SBDeptID = #{sbdeptId} and SendState in(21,23) and BackState in (0,12,22) and IsDel=0 " +
            "and DATEDIFF(day, GETDATE(), BackLimit) IN (1,0)" +
            "[[and (select WorkFormNO from tWorkFormBase where PkId=WfId) = #{sendBack.myTwfNO}]] [[and SDeptName =#{sendBack.sdeptName}]]")
    List<Map<String, Object>> muBlueSJson(HashMap<String, Object> params);

    /**
     * 查找超期工单列表数据（超出办理期限工单）
     *
     * @param params 查询条件
     * @return 列表数据
     */
    @Select("select PkId as myPkVal,WfId,OriLevel,SDeptID as fmDept,SBDeptID as sbDept," +
            "(select WorkFormNO from tWorkFormBase where PkId=WfId) as myTwfNO,(select WsTopic from tWorkFormBase where PkId=WfId) as myTwfTopic," +
            "SeqName,SBDeptName,SortName,DealName,convert(varchar(10),BackLimit,20) as bkLimit,SDeptName,convert(varchar(10),GetTime,20) as acDate," +
            "BackState as bkState,BackRemark as acRemark,PkId as opDeal,BackDesc as backDesc from tWfSendBack " +
            "where  SBDeptID = #{sbdeptId} and SendState in(21,23) and BackState in (0,12,22) and IsDel=0 and getdate() &gt; BackLimit" +
            "[[and (select WorkFormNO from tWorkFormBase where PkId=WfId) = #{sendBack.myTwfNO}]] [[and SDeptName =#{sendBack.sdeptName}]]")
    List<Map<String, Object>> muRedSJson(HashMap<String, Object> params);

    /**
     * 查找本区办理的工单列表
     *
     * @param params 查询条件
     * @return 列表数据
     */
    @Select("select PkId as myPkVal,WfId,GetDealPK as telId," +
            "(select WorkFormNO from tWorkFormBase where PkId=WfId) as myTwfNO," +
            "(select WsTopic from tWorkFormBase where PkId=WfId) as myTwfTopic," +
            "SDeptName,SeqName,SBDeptName,SortName,DealName,convert(varchar(10),BackLimit,20) as bkLimit," +
            "convert(varchar(10),BackTime,20) as bkDate,BackState as chgBack,BackRemark FROM [tWfSendBack] " +
            "WHERE SendTime BETWEEN #{startTime} AND #{endTime} AND SBDeptID = #{sbdeptId} AND BackState in (11,21) AND IsDel = 0 " +
            "[[and (select WorkFormNO from tWorkFormBase where PkId=WfId) = #{sendBack.myTwfNO}]] [[and SDeptName =#{sendBack.sdeptName}]]")
    List<Map<String, Object>> rptReplyOverListJson(HashMap<String, Object> params);

    /**
     * 查找本区未转派工单列表
     *
     * @param params 查询条件
     * @return 列表数据
     */
    @Select("select PkId as myPkVal,WfId,(select WorkFormNO from tWorkFormBase where PkId=WfId) as myTwfNO," +
            "(select WsTopic from tWorkFormBase where PkId=WfId) as myTwfTopic,SeqName,SBDeptName,SortName,SDeptName," +
            "convert(varchar(10),BackLimit,20) BackLimit,convert(varchar(10),GetTime,20) as acDate,BackRemark as acDesc FROM [tWfSendBack] " +
            "WHERE  SBDeptID = #{sbdeptId} and SendState=22 and IsDel=0 " +
            "[[and (select WorkFormNO from tWorkFormBase where PkId=WfId) = #{sendBack.myTwfNO}]] [[and SDeptName =#{sendBack.sdeptName}]]")
    List<Map<String, Object>> rptSendWaitListJson(HashMap<String, Object> params);

    @Select("select PkId as myPkVal,WfId,(select WorkFormNO from tWorkFormBase where PkId=WfId) as myTwfNO," +
            "(select WsTopic from tWorkFormBase where PkId=WfId) as myTwfTopic,SeqName,SBDeptName,SortName,SDeptName," +
            "convert(varchar(10),BackLimit,20) BackLimit,convert(varchar(10),GetTime,20) as acDate,BackRemark as acDesc FROM [tWfSendBack] " +
            "WHERE  SBDeptID = #{sbdeptId} and SendState=22 and IsDel=0 and DATEDIFF(day, GETDATE(), BackLimit) > -30 " +
            "[[and (select WorkFormNO from tWorkFormBase where PkId=WfId) = #{sendBack.myTwfNO}]] [[and SDeptName =#{sendBack.sdeptName}]]")
    List<Map<String, Object>> rptSendWaitListJson_gxq(HashMap<String, Object> params);

    /**
     * 查找本区被市级拒退工单列表
     *
     * @param params 查询条件
     * @return 列表数据
     */
    @Select("select PkId as myPkVal,WfId,(select WorkFormNO from tWorkFormBase where PkId=WfId) as myTwfNO," +
            "(select WsTopic from tWorkFormBase where PkId=WfId) as myTwfTopic,SeqName,SBDeptName,SortName,DealName," +
            "convert(varchar(10),BackLimit,20) bkLimit,SDeptName,convert(varchar(10),SendTime,20) sdDate,SendRemark,SAttachPath FROM [tWfSendBack] " +
            "WHERE  SBDeptID = #{sbdeptId} And SendState=51 and dbo.frTelWFStep(WfId)>399 and IsDel=0 " +
            "[[and (select WorkFormNO from tWorkFormBase where PkId=WfId) = #{sendBack.myTwfNO}]] [[and SDeptName =#{sendBack.sdeptName}]]")
    List<Map<String, Object>> rptNotPassListJson(HashMap<String, Object> params);

    /**
     * 查找本区已退工单列表
     *
     * @param params 查询条件
     * @return 列表数据
     */
    @Select("select PkId as myPkVal,WfId,GetDealPK as telId," +
            "(select WorkFormNO from tWorkFormBase where PkId=WfId) as myTwfNO," +
            "(select WsTopic from tWorkFormBase where PkId=WfId) as myTwfTopic," +
            "SeqName,SBDeptName,SortName,DealName,convert(varchar(10),BackLimit,20) bkLimit," +
            "SDeptName,convert(varchar(10),SendTime,20) sdDate,convert(varchar(10),GetTime,20) as bkDate," +
            "BackRemark from tWfSendBack where  SBDeptID=#{sbdeptId} and SendState=40 and IsDel=0 " +
            "[[and (select WorkFormNO from tWorkFormBase where PkId=WfId) = #{sendBack.myTwfNO}]] [[and SDeptName =#{sendBack.sdeptName}]]")
    List<Map<String, Object>> rptDeptBackJson(HashMap<String, Object> params);

    /**
     * 查找本级未签收工单列表
     *
     * @param  查询条件
     * @return 列表数据
     */
    @Select("select PkId,WfId,(select WorkFormNO from tWorkFormBase where PkId=WfId) as myTwfNO," +
            "(select WsTopic from tWorkFormBase where PkId=WfId) as myTwfTopic,SeqName,SBDeptName,SortName," +
            "DealName,convert(varchar(10),BackLimit,20) bkLimit,SDeptName,convert(varchar(10),SendTime,20) sdDate," +
            "SendRemark,PkId as opDeal,SAttachPath,(select mark from tWorkFormBase where PkId=WfId) as Mark " +
            "from tWfSendBack where  SBDeptID=#{sbdeptId} and SendState in (10,11) and dbo.frTelWFStep(WfId)>399 and IsDel=0 " +
            "[[and (select WorkFormNO from tWorkFormBase where PkId=WfId) = #{sendBack.myTwfNO}]][[and SBDeptName=#{sendBack.sbdeptName}]]")
    List<Map<String, Object>> rptSignNotJson(@Param("sbdeptId") String sbdeptId, @Param("sendBack") TwfSendBackEty sendBackEty);

    /**
     * 查找本级未签收工单列表
     * gxq
     * @param
     * @return 列表数据
     */
    @Select("select PkId,WfId,(select WorkFormNO from tWorkFormBase where PkId=WfId) as myTwfNO," +
            "(select WsTopic from tWorkFormBase where PkId=WfId) as myTwfTopic,SeqName,SBDeptName,SortName," +
            "DealName,convert(varchar(10),BackLimit,20) bkLimit,SDeptName,convert(varchar(10),SendTime,20) sdDate," +
            "SendRemark,PkId as opDeal,SAttachPath,(select mark from tWorkFormBase where PkId=WfId) as Mark " +
            "from tWfSendBack where  SBDeptID=#{sbdeptId} and SendState in (10,11) and dbo.frTelWFStep(WfId)>399 and dbo.frTelWFStep(WfId) &lt; 900 and IsDel=0 and BackTime is null " +
            "[[and (select WorkFormNO from tWorkFormBase where PkId=WfId) = #{sendBack.myTwfNO}]][[and SBDeptName=#{sendBack.sbdeptName}]]")
    List<Map<String, Object>> rptSignNotJson_gxq(@Param("sbdeptId") String sbdeptId, @Param("sendBack") TwfSendBackEty sendBackEty);



    /**
     * 下级办理中T 列表数据
     *
     * @param
     * @param qc
     * @return
     */
    @Select("select PkId as myPkVal,WfId as twfpk,GetDealPK as telpk,SDeptID as fDNo,(select WorkFormNO from tWorkFormBase where PkId=WfId) as myTwfNO," +
            " (select WsTopic from tWorkFormBase where PkId=WfId) as myTwfTopic,isUrge," +
            "(select fmContent from tWorkFormBase where PkId=WfId) as FmContent," +
            "SBDeptName,SBDeptID,SeqName,SortName,convert(varchar(10),BackLimit,20) BackLimit," +
            " SendRemark,SendState,BackState,BackState as chgChk,SAttachPath,pid from tWfSendBack where SDeptID=#{qc.userDeptId} and SendState in (10,21,22,23) " +
            " and BackState in (0,10,12) and IsDel=0 [[and (select WorkFormNO from tWorkFormBase where PkId=WfId) = #{qc.workFormNO}]] " +
            "[[and SDeptName = #{qc.sdeptName}]] [[and SBDeptName = #{qc.sbDeptName}]]" +
            "[[and convert(varchar(10),GetTime,120) &gt;= #{qc.signBeginTime}]] [[and convert(varchar(10),GetTime,120) &lt;= #{qc.signEndTime}]]" +
            "[[and convert(varchar(10),BackLimit,120) &gt;= #{qc.beginTime}]] [[and convert(varchar(10),BackLimit,120) &lt;= #{qc.endTime}]]")
    List<Map<String, Object>> listSonWaitJson(@Param("qc") QueryConditionVo qc);

    @Select("select PkId as myPkVal,WfId as twfpk,GetDealPK as telpk,SDeptID as fDNo,(select WorkFormNO from tWorkFormBase where PkId=WfId) as myTwfNO," +
            " (select WsTopic from tWorkFormBase where PkId=WfId) as myTwfTopic,isUrge," +
            "(select fmContent from tWorkFormBase where PkId=WfId) as FmContent," +
            "SBDeptName,SBDeptID,SeqName,SortName,convert(varchar(10),BackLimit,20) BackLimit," +
            " SendRemark,SendState,BackState,BackState as chgChk,SAttachPath,pid from tWfSendBack where SDeptID=#{qc.userDeptId} and SendState in (10,21,22,23) and isUrge = 1 " +
            " and BackState in (0,10,12) and IsDel=0 [[and (select WorkFormNO from tWorkFormBase where PkId=WfId) = #{qc.workFormNO}]] " +
            "[[and SDeptName = #{qc.sdeptName}]] [[and SBDeptName = #{qc.sbDeptName}]]" +
            "[[and convert(varchar(10),GetTime,120) &gt;= #{qc.signBeginTime}]] [[and convert(varchar(10),GetTime,120) &lt;= #{qc.signEndTime}]]" +
            "[[and convert(varchar(10),BackLimit,120) &gt;= #{qc.beginTime}]] [[and convert(varchar(10),BackLimit,120) &lt;= #{qc.endTime}]]")
    List<Map<String, Object>> listSonWaitJson1(@Param("qc") QueryConditionVo qc);


    @Select("select PkId as myPkVal,WfId as twfpk,GetDealPK as telpk,SDeptID as fDNo,(select WorkFormNO from tWorkFormBase where PkId=WfId) as myTwfNO," +
            " (select WsTopic from tWorkFormBase where PkId=WfId) as myTwfTopic,isUrge," +
            "(select fmContent from tWorkFormBase where PkId=WfId) as FmContent," +
            "SBDeptName,SBDeptID,SeqName,SortName,convert(varchar(10),BackLimit,20) BackLimit," +
            " SendRemark,SendState,BackState,BackState as chgChk,SAttachPath,pid from tWfSendBack where SDeptID=#{qc.userDeptId} and SendState in (10,21,22,23) " +
            " and BackState in (0,10,12) and IsDel=0 and dbo.frTelWFStep(WfId) > 399 and dbo.frTelWFStep(WfId) &lt; 900 and DATEDIFF(day,GetDate(),BackLimit) > -30 [[and (select WorkFormNO from tWorkFormBase where PkId=WfId) = #{qc.workFormNO}]] " +
            "[[and SDeptName = #{qc.sdeptName}]] [[and SBDeptName = #{qc.sbDeptName}]]" +
            "[[and convert(varchar(10),GetTime,120) &gt;= #{qc.signBeginTime}]] [[and convert(varchar(10),GetTime,120) &lt;= #{qc.signEndTime}]]" +
            "[[and convert(varchar(10),BackLimit,120) &gt;= #{qc.beginTime}]] [[and convert(varchar(10),BackLimit,120) &lt;= #{qc.endTime}]]")
    List<Map<String, Object>> listSonWaitJson_gxq(@Param("qc") QueryConditionVo qc);

    @Select("select PkId as myPkVal,WfId as twfpk,GetDealPK as telpk,SDeptID as fDNo,(select WorkFormNO from tWorkFormBase where PkId=WfId) as myTwfNO," +
            " (select WsTopic from tWorkFormBase where PkId=WfId) as myTwfTopic,isUrge," +
            "(select fmContent from tWorkFormBase where PkId=WfId) as FmContent," +
            "SBDeptName,SBDeptID,SeqName,SortName,convert(varchar(10),BackLimit,20) BackLimit," +
            " SendRemark,SendState,BackState,BackState as chgChk,SAttachPath,pid from tWfSendBack where SDeptID=#{qc.userDeptId} and SendState in (10,21,22,23) and isUrge = 1 " +
            " and BackState in (0,10,12) and IsDel=0 and dbo.frTelWFStep(WfId) > 399 and dbo.frTelWFStep(WfId) &lt; 900 and DATEDIFF(day,GetDate(),BackLimit) > -30 [[and (select WorkFormNO from tWorkFormBase where PkId=WfId) = #{qc.workFormNO}]] " +
            "[[and SDeptName = #{qc.sdeptName}]] [[and SBDeptName = #{qc.sbDeptName}]]" +
            "[[and convert(varchar(10),GetTime,120) &gt;= #{qc.signBeginTime}]] [[and convert(varchar(10),GetTime,120) &lt;= #{qc.signEndTime}]]" +
            "[[and convert(varchar(10),BackLimit,120) &gt;= #{qc.beginTime}]] [[and convert(varchar(10),BackLimit,120) &lt;= #{qc.endTime}]]")
    List<Map<String, Object>> listSonWaitJson1_gxq(@Param("qc") QueryConditionVo qc);

    /**
     * 下级已办毕T 列表数据
     * BackState 21 上级通过  22 上级不通过
     * @param workFormNo
     * @param sdeptName
     * @param deptId
     * @return
     */
    @Select("select PkId as myPkVal,WfId as twfpk,GetDealPK as telpk,SDeptID as fDNo, " +
            "(select WorkFormNO from tWorkFormBase where PkId=WfId) as myTwfNO, " +
            "(select WsTopic from tWorkFormBase where PkId=WfId) as myTwfTopic, " +
            "(select fmContent from tWorkFormBase where PkId=WfId) as FmContent,SBDeptName,SeqName,SortName, " +
            "convert(varchar(10),BackLimit,20) BackLimit,SendRemark,SendState,BackState as chgChk,BackState " +
            "from tWfSendBack where SDeptID=#{deptId} and SendState in (21,22,23) and BackState in (21,22) and IsDel=0 " +
            "[[and (select WorkFormNO from tWorkFormBase where PkId=WfId) = #{workFormNo}]] " +
            "[[and SDeptName =#{sdeptName}]]")
    List<Map<String, Object>> listSonOverJson(@Param("workFormNo") String workFormNo, @Param("sdeptName") String sdeptName, @Param("deptId") String deptId);


    /**
     * 下级已办毕T 待处理列表数据
     * BackState 10 未审 11 自审通过 12 自审不通过
     * @param workFormNo
     * @param sbDeptName
     * @param deptId
     * @return
     */
    @Select("select t1.PkId as myPkVal,t1.PkId as pkid,WfId as twfpk,t1.GetDealPK as telpk,SDeptID as fDNo," +
            "t2.WorkFormNO as myTwfNO,t2.WsTopic as myTwfTopic,t2.fmContent as FmContent,SBDeptName,SeqName,SortName," +
            "convert(varchar(10),BackLimit,20) BackLimit,SendRemark,SendState,BackState as chgChk,BackState,pid " +
            " from tWfSendBack t1 left join tWorkFormBase t2 on t1.WfId = t2.PkId " +
            "where t1.SDeptID=#{deptId} and t1.SendState in (21,22,23) and t1.BackState in (10,11) and t1.IsDel=0 and t2.IsDel = 0 " +
            "[[and t2.WorkFormNO = #{workFormNo}]] " +
            "[[and t1.SBDeptName =#{sbDeptName}]]")
    List<Map<String, Object>> listSonOverUntreatedJson(@Param("workFormNo") String workFormNo, @Param("sbDeptName") String sbDeptName, @Param("deptId") String deptId);

    /**
     * 下级已办毕T 待处理列表数据
     * BackState 10 未审 11 自审通过 12 自审不通过
     * @param workFormNo
     * @param sbDeptName
     * @param deptId
     * @return
     */
    @Select("select t1.PkId as myPkVal,t1.PkId as pkid,WfId as twfpk,t1.GetDealPK as telpk,SDeptID as fDNo," +
            "t2.WorkFormNO as myTwfNO,t2.WsTopic as myTwfTopic,t2.fmContent as FmContent,SBDeptName,SeqName,SortName," +
            "convert(varchar(10),BackLimit,20) BackLimit,SendRemark,SendState,BackState as chgChk,BackState,pid " +
            " from tWfSendBack t1 left join tWorkFormBase t2 on t1.WfId = t2.PkId " +
            "where t1.SDeptID=#{deptId} and t1.SendState in (21,22,23) and t1.BackState in (10,11) and t1.IsDel=0 and t2.IsDel = 0 and DATEDIFF(day,GetDate(),BackLimit) > -15 " +
            "[[and t2.WorkFormNO = #{workFormNo}]] " +
            "[[and t1.SBDeptName =#{sbDeptName}]]")
    List<Map<String, Object>> listSonOverUntreatedJson_gxq(@Param("workFormNo") String workFormNo, @Param("sbDeptName") String sbDeptName, @Param("deptId") String deptId);


    /**
     * 下级已办毕T 已处理列表数据
     * BackState 21 上级通过  22 上级不通过
     * @param workFormNo
     * @param sbDeptName
     * @param deptId
     * @return
     */
    @Select("select t1.PkId as myPkVal,t1.PkId as pkid,WfId as twfpk,t1.GetDealPK as telpk,SDeptID as fDNo," +
            "t2.WorkFormNO as myTwfNO,t2.WsTopic as myTwfTopic,t2.fmContent as FmContent,SBDeptName,SeqName,SortName," +
            "convert(varchar(10),BackLimit,20) BackLimit,SendRemark,SendState,BackState as chgChk,BackState,pid " +
            " from tWfSendBack t1 left join tWorkFormBase t2 on t1.WfId = t2.PkId " +
            "where t1.SDeptID=#{deptId} and t1.SendState in (21,22,23) and t1.BackState in (21,22) and t1.IsDel=0 and t2.IsDel = 0 " +
            "[[and t2.WorkFormNO = #{workFormNo}]] " +
            "[[and t1.SBDeptName =#{sbDeptName}]]")
    List<Map<String, Object>> listSonOverTreatedJson(@Param("workFormNo") String workFormNo, @Param("sbDeptName") String sbDeptName, @Param("deptId") String deptId);

    /**
     * 加载派单管理列表数据
     *
     * @param sendBack 查询条件
     * @param deptId   部门编号
     * @return 列表数据
     */
    @Select("select PkId as myPkVal,WfId,SeqName,SortName,DealName,SBDeptName,SendDesc,SDeptName," +
            "convert(varchar(19),BackLimit,20) as backLimit,SUserName,convert(varchar(19),SendTime,20) as sendTime," +
            "SendState as chgState,convert(varchar(19),GetTime,20) as getTime,GetPerson,BUserName,isGoBack," +
            "convert(varchar(19),BackTime,20) as backTime from tWfSendBack " +
            "where WfId=#{param1.wfId} and SDeptID=#{param2} and IsDel=0 " +
            "[[and SBDeptName = #{param1.sbdeptName}]] [[and SortName = #{param1.sortName}]]")
    List<Map<String, Object>> sendBackJson(TwfSendBackEty sendBack, Long deptId);

    /**
     * 检查二级部门下派的派单记录是否有下级回复
     *
     * @param wfId    工单id
     * @param sdeptId 拟派部门编号
     * @return 已回复/''
     */
    @Select("SELECT PkId,BackDesc FROM tWfSendBack where IsDel=0 and SendState not in (40) and wfId=#{param1} AND sdeptId=#{param2}")
    List<CheckSendBack> checkSendBack(Integer wfId, String sdeptId);

    /**
     * 查找下级部门办理件 取每个部门最新的回复
     *
     * @param wfId    工单id
     * @param sdeptId 部门编号
     * @return 派单列表
     */
    @Select("SELECT PkId,SeqName,SortName,SBDeptID,SBDeptName,BDutyDept,BUserName,BDutyTel,convert(varchar(19),BackTime,20) as backTime,BackDesc,BackState From tWfSendBack " +
            "where IsDel = 0 and SendState not in(30,40) and wfId = #{wfId} and sdeptId = #{sdeptId} " +
            "and PkId in(select max(PkId) from tWfSendBack where IsDel = 0 AND SendState NOT IN ( 30, 40) " +
            "AND wfId = #{wfId} AND sdeptId = #{sdeptId} GROUP BY SBDeptID) " +
            "order by BackTime desc")
    List<TwfSendBackEty> listSendDeptSon(@Param("wfId") Integer wfId, @Param("sdeptId") Long sdeptId);

    /**
     * 查找下级部门办理件 取每个部门最新的回复
     *
     * @param wfId    工单id
     * @param sdeptId 部门编号
     * @return 派单列表
     */
    @Select("select PkId,SortName,SBDeptID,SBDeptName,BDutyDept,BUserName,BDutyTel,convert(varchar(19),BackTime,20) as backTime,BackDesc,BackState,row_number() over(partition by SBDeptID order by SendTime desc) groupIndex " +
            "from tWfSendBack where IsDel = 0 and SendState not in(30,40)  and sdeptId = #{sdeptId} and WfId = #{wfId} ")
    List<TwfSendBackEty> findSubDeptHandleWF(@Param("wfId") Integer wfId, @Param("sdeptId") Long sdeptId);

    /**
     * 查找下级部门办理件 通过当前派单id作为pid查找
     *
     * @param pkId
     * @param sdeptId
     * @return
     */
    @Select("SELECT PkId,SeqName,SortName,SBDeptName,BDutyDept,BUserName,BDutyTel,convert(varchar(19),BackTime,20) as backTime,BackDesc,BackState From tWfSendBack " +
            "where IsDel = 0 and SendState not in(30,40) and pid = #{pkId} and sdeptId = #{sdeptId} order by BackTime desc")
    List<TwfSendBackEty> listSendSubDept(@Param("pkId")Integer pkId, @Param("sdeptId") Long sdeptId);

    /**
     * 查找下级退回 待处理的工单
     * @param params 条件
     * @return 列表数据
     */
    @Select("select PkId as myPkVal,WfId as twfpk,GetDealPK as telpk,SDeptID as fDNo," +
            "(select WorkFormNO from tWorkFormBase where PkId=WfId) as WfId,(select WsTopic from tWorkFormBase where PkId=WfId) as myTwfTopic," +
            "SBDeptName,SeqName,SortName,convert(varchar(10),BackLimit,20) BackLimit,SendRemark,SendState,BackState,BackState as chgChk,SAttachPath from tWfSendBack" +
            " where SDeptID=#{deptId} and SendState=40 and FlagInt = 1 and IsDel=0 " +
            "[[and (select WorkFormNO from tWorkFormBase where PkId=WfId) = #{workFormNo}]] [[and SDeptName =#{sdeptName}]]")
    List<Map<String, Object>> listSonNABackJson(HashMap<String, Object> params);

    @Select("select PkId as myPkVal,WfId as twfpk,GetDealPK as telpk,SDeptID as fDNo," +
            "(select WorkFormNO from tWorkFormBase where PkId=WfId) as WfId,(select WsTopic from tWorkFormBase where PkId=WfId) as myTwfTopic," +
            "SBDeptName,SeqName,SortName,convert(varchar(10),BackLimit,20) BackLimit,SendRemark,SendState,BackState,BackState as chgChk,SAttachPath from tWfSendBack" +
            " where SDeptID=#{deptId} and SendState=40 and FlagInt = 1 and IsDel=0 and DATEDIFF(day, GetDate(), BackLimit) > -15 " +
            "[[and (select WorkFormNO from tWorkFormBase where PkId=WfId) = #{workFormNo}]] [[and SDeptName =#{sdeptName}]]")
    List<Map<String, Object>> listSonNABackJson_gxq(HashMap<String, Object> params);

    /**
     * 查找下级退回 已处理的工单
     * @param params 条件
     * @return 列表数据
     */
    @Select("select PkId as myPkVal,WfId as twfpk,GetDealPK as telpk,SDeptID as fDNo," +
            "(select WorkFormNO from tWorkFormBase where PkId=WfId) as WfId,(select WsTopic from tWorkFormBase where PkId=WfId) as myTwfTopic," +
            "SBDeptName,SeqName,SortName,convert(varchar(10),BackLimit,20) BackLimit,SendRemark,SendState,BackState,BackState as chgChk,SAttachPath,pid from tWfSendBack" +
            " where SDeptID=#{deptId} and SendState in(40,51) and flagInt=0 and IsDel=0 " +
            "[[and (select WorkFormNO from tWorkFormBase where PkId=WfId) = #{workFormNo}]] [[and SDeptName =#{sdeptName}]]")
    List<Map<String, Object>> listSonABackJson(HashMap<String, Object> params);

    /**
     * 查找下级退回的全退工单
     * @param params 条件
     * @return 列表数据
     */
    @Select("select PkId as myPkVal,WfId as twfpk,GetDealPK as telpk,SDeptID as fDNo," +
            "(select WorkFormNO from tWorkFormBase where PkId=WfId) as WfId," +
            "(select WsTopic from tWorkFormBase where PkId=WfId) as myTwfTopic," +
            "SBDeptName,SeqName,SortName,convert(varchar(10),BackLimit,20) BackLimit," +
            "SendRemark,SendState,BackState,BackState as chgChk,SAttachPath from tWfSendBack " +
            "where dbo.frTelSBIsAllBack(WfId,#{deptId}) = 1 and SBDeptID=#{deptId} and IsDel=0 " +
            "[[and SendTime &gt; ${timeDefault}]] " +
            "[[and SendTime &gt; #{beginTime}]] [[and SendTime &lt; #{endTime}]] " +
            "[[and (select WorkFormNO from tWorkFormBase where PkId=WfId) = #{workFormNo}]] [[and SDeptName =#{sdeptName}]]")
    List<Map<String, Object>> listAllSonABackJson(HashMap<String, Object> params);

    /**
     * 查询下级部门的电话未签收、未回复、退回和超期情况数据统计
     *  2023/1/3
     *  @Param params
     */
//    @Select("select \n" +
//            "SBDeptName as deptName,\n" +
//            "sum(case when SendTime BETWEEN #{startTime} AND #{endTime}  and SendState in (10,11) and dbo.frTelWFStep(WfId)>399 and IsDel=0 then 1 else 0 end) as subNotSignTelNum,\n" +
//            "sum(case when SendState in(21,23) and BackState in (0,12,22) and IsDel=0 then 1 else 0 end) as subNotReplyTelNum,\n" +
//            "sum(case when SendState=40 and BackState=11 and flagInt=1 and IsDel=0 then 1 else 0 end) as subBackTelNum,\n" +
//            "sum(case when SendTime BETWEEN #{startTime} AND #{endTime}  and SendState in(21,23) and BackState in (0,12,22) and IsDel=0  then 1 else 0 end) as subBlueTelNum\n" +
//            "from tWfSendBack\n" +
//            "where  SDeptID=#{deptId} and IsDel =0\n" +
//            "group by SBDeptName")
    @Select(" select \n" +
            "       subDept.deptName,\n" +
            "       sum(case when  SendState in (10,11) and dbo.frTelWFStep(WfId)>399 and IsDel=0 then 1 else 0 end) as subNotSignTelNum,\n" +
            "       sum(case when SendState in(21,23) and BackState in (0,12,22) and IsDel=0 then 1 else 0 end) as subNotReplyTelNum,\n" +
            "       sum(case when SendState=40 and BackState=11 and flagInt=1 and IsDel=0 then 1 else 0 end) as subBackTelNum,\n" +
            "       sum(case when  SendState in(21,23) and BackState in (0,12,22) and IsDel=0  then 1 else 0 end) as subBlueTelNum\n" +
            "       from (SELECT noUnit,deptShort,deptName FROM bUserDept WHERE noParent=#{deptId} AND useState=1 AND isDel=0  ) as subDept\n" +
            "       left join tWfSendBack twsb on twsb.SBDeptName =subDept.deptName\n" +
            "       group by subDept.deptName")
    List<Map<String,Object>> listTelSubStatisticsJson(HashMap<String, Object> params);

    /**
     * @Description: 查询下级部门的电话未签收、未回复、退回和超期情况数据统计
     * 2023/2/1
     * @Param: [deptId]
     * @return: List<Map<String,Object>>
     */
    @Select("{call ReportTelStatistics(#{deptId,jdbcType=VARCHAR,mode=IN})}")
    @Options(statementType= StatementType.CALLABLE)
    List<Map<String,Object>> listTelSubStatistics(@Param("deptId") String deptId);


    @Select("{call ReportTelStatistics_gxq(#{deptId,jdbcType=VARCHAR,mode=IN})}")
    @Options(statementType= StatementType.CALLABLE)
    List<Map<String,Object>> listTelSubStatistics_gxq(@Param("deptId") String deptId);


    /**
     * 市级已删除数据
     * @param twfSendBackEty 拟派工单实体
     * @param deptId 部门id
     * @return
     */
//    @Select("SELECT * FROM (SELECT t1.PkId,t1.WfId,t2.WorkFormNO AS myTwfNO,t2.WsTopic AS myTwfTopic,t2.FmContent,SeqName,t2.SpareString," +
//            " row_number() over(partition by t1.WfId order by sendState desc) rb," +
//            " SBDeptName,SortName,DealName,CONVERT(VARCHAR(10),BackLimit,20) bkLimit,SDeptName,sendState," +
//            " CONVERT(VARCHAR(10),SendTime,20) sdDate,SendRemark FROM" +
//            " tWfSendBack t1 inner join tWorkFormBase t2 on t1.WfId=t2.PkId" +
//            " WHERE t1.IsDel=1 AND t2.IsDel=0 AND SBDeptID=#{deptId} AND dbo.frTelWFStep (WfId)>399" +
//            " [[and WorkFormNO=#{twf.myTwfNO}]] [[and SDeptName =#{twf.sdeptName}]])" +
//            " as A where rb = 1")
    @Select("SELECT t1.PkId,t1.WfId,t2.WorkFormNO AS myTwfNO,t2.WsTopic AS myTwfTopic,t2.FmContent,SeqName,t2.SpareString," +
            " SBDeptName,SortName,DealName,CONVERT(VARCHAR(10),BackLimit,20) bkLimit,SDeptName,sendState," +
            " CONVERT(VARCHAR(10),SendTime,20) sdDate,SendRemark FROM" +
            " tWfSendBack t1 inner join tWorkFormBase t2 on t1.WfId=t2.PkId" +
            " WHERE t2.IsDel=1 AND SBDeptID=#{deptId}" +
            " [[and WorkFormNO=#{twf.myTwfNO}]] [[and SDeptName =#{twf.sdeptName}]]")
    List<Map<String,Object>> deletedTelWFList(@Param("twf") TwfSendBackEty twfSendBackEty,@Param("deptId")String deptId);

    /**
     * 删除工单被派单次数
     * @param twfSendBackEty 拟派工单实体
     * @param deptId 部门id
     * @return
     */
    @Select(" WITH tabs AS (SELECT t2.WorkFormNO AS myTwfNO,row_number() over(partition by t1.WfId order by sendState desc) rb " +
            " FROM tWfSendBack t1 inner join tWorkFormBase t2 on t1.WfId=t2.PkId " +
            " WHERE t1.IsDel=1 AND t2.IsDel=0 AND SBDeptID=#{deptId} AND dbo.frTelWFStep (WfId)>399" +
            " [[and WorkFormNO=#{twf.myTwfNO}]] [[and SDeptName =#{twf.sdeptName}]] " +
            ")" +
            " SELECT MAX(rb) as sendOrderNum,myTwfNO from tabs group by myTwfNO ")
    List<Map<String,Object>> sendOrderNums(@Param("twf") TwfSendBackEty twfSendBackEty,@Param("deptId")String deptId);

    /**
     * 催办派单
     * @param sbId 派单id
     * @return
     */
    @Update("update tWfSendBack set isUrge = 1  where PkId = #{sbId}")
    int updateUrgeTransact(@Param("sbId") String sbId);

    /**
     * 市级未签收列表数据
     *
     * @param twfSendBackEty
     * @param deptId
     * @return
     */
    @Select("SELECT t1.PkId,t1.WfId,t2.WorkFormNO AS myTwfNO,t2.WsTopic AS myTwfTopic,t2.FmContent,SeqName," +
            " SBDeptName,SortName,DealName,CONVERT(VARCHAR(10),BackLimit,20) bkLimit,SDeptName," +
            " CONVERT(VARCHAR(10),SendTime,20) sdDate,SendRemark,SAttachPath,Mark FROM" +
            " tWfSendBack t1 inner join tWorkFormBase t2 on t1.WfId=t2.PkId" +
            " WHERE t1.IsDel=0 AND t2.IsDel=0 AND SBDeptID=#{deptId} AND SendState IN(10,11)" +
            " AND dbo.frTelWFStep (WfId)>399 " +
            "[[and WorkFormNO =#{twf.myTwfNO}]]" +
            "[[and SBDeptName =#{twf.sbdeptName}]]" +
            "[[and WsTopic like '%'+#{twf.myTwfTopic}+'%']]" +
            "[[and FmContent like '%'+#{twf.fmContent}+'%']]" +
            "")
    List<TwfSendBackEty> notSignList(@Param("twf") TwfSendBackEty twfSendBackEty, @Param("deptId") String deptId);

    /**
     * 查找待本部门回复的工单数据
     *
     * @param deptId 部门id
     * @return 工单列表数据
     */
    @Select("select t1.PkId as pkId,t1.WfId as wfId,OriLevel,SDeptID as fmDept,SBDeptID as sbDept,isUrge," +
            "t2.WorkFormNO as myTwfNO,t2.WsTopic as myTwfTopic,t2.FmContent,SeqName,SBDeptName,SortName,DealName,convert(varchar(10),BackLimit,20) as bkLimit," +
            "SDeptName,convert(varchar(10),GetTime,20) as acDate," +
            "BackState as bkState,BackRemark as acRemark,t1.PkId as opDeal,BackDesc as backDesc,subBackState cbackDesc " +
            "from tWfSendBack t1 inner join tWorkFormBase t2 on t1.WfId=t2.PkId " +
            "where t1.SBDeptID=#{sbdeptId} and t1.SendState in(21,23) and t1.BackState in (0,12,22) and t1.IsDel=0 " +
            "[[and WsTopic like '%'+#{twf.myTwfTopic}+'%']]" +
            "[[and FmContent like '%'+#{twf.fmContent}+'%']]")
    List<Map<String, Object>> waitReplyListJson(@Param("twf") TwfSendBackEty twfSendBackEty, @Param("sbdeptId") String deptId);

    /**
     * 查找当前部门办理件
     *
     * @param wfId    工单id
     * @param deptId 部门编号
     * @return 派单列表
     */
    @Select("SELECT PkId,SeqName,SortName,sortCode,SBDeptName,BDutyDept,BUserName,BDutyTel,convert(varchar(19),BackTime,20) as backTime,BackDesc,BackState,sdeptName,sdeptId,sbdeptId " +
            "From tWfSendBack where IsDel = 0 and SendState not in(30,40) and wfId = #{wfId} and SBDeptID = #{deptId} " +
            "and PkId in(select max(PkId) from tWfSendBack where IsDel = 0 AND SendState NOT IN ( 30, 40) " +
            "AND wfId = #{wfId} AND SBDeptID = #{deptId} GROUP BY SBDeptID) order by BackTime desc")
    TwfSendBackEty curDeptHandleSend(@Param("wfId") Integer wfId, @Param("deptId") String deptId);

    /**
     * 查询未处理电话工单数据
     * @param deptId 办理部门
     * @param twfSendBackEty 电话工单
     * @return
     */
    @Select(" SELECT t1.PkId,t1.WfId,t2.WorkFormNO AS myTwfNO,t2.WsTopic AS myTwfTopic,t2.FmContent,SeqName,t2.SpareString," +
            " SBDeptName,SortName,DealName,CONVERT(VARCHAR(10),BackLimit,20) bkLimit,SDeptName,SendState,BackState," +
            " CONVERT(VARCHAR(10),SendTime,20) sdDate,SendRemark FROM" +
            " tWfSendBack t1 inner join tWorkFormBase t2 on t1.WfId=t2.PkId" +
            " WHERE t1.SBDeptID=#{sbdeptId} AND t1.isDel=0 AND t1.SendState in(10,11,40,51) AND dbo.frTelWFStep(WfId)>399 AND t1.SendTime &lt;= getdate() and SendTime &gt;= dateadd(year,-1,getdate()) " +
            " [[AND WorkFormNO=#{tel.myTwfNO}]] " +
            " [[AND SDeptName =#{tel.sdeptName}]]")
    List<Map<String, Object>> notHandleTelJson(@Param("sbdeptId") String deptId, @Param("tel") TwfSendBackEty twfSendBackEty);

    @Select(" SELECT t1.PkId,t1.WfId,t2.WorkFormNO AS myTwfNO,t2.WsTopic AS myTwfTopic,t2.FmContent,SeqName,t2.SpareString," +
            " SBDeptName,SortName,DealName,CONVERT(VARCHAR(10),BackLimit,20) bkLimit,SDeptName,SendState,BackState," +
            " CONVERT(VARCHAR(10),SendTime,20) sdDate,SendRemark FROM" +
            " tWfSendBack t1 inner join tWorkFormBase t2 on t1.WfId=t2.PkId" +
            " WHERE t1.SBDeptID=#{sbdeptId} AND t1.isDel=0 AND t1.SendState in(10,11,40,51) AND dbo.frTelWFStep(WfId)>399 AND t1.SendTime &lt;= getdate() and SendTime &gt;= dateadd(year,-1,getdate()) and DATEDIFF(day, GETDATE(), t1.BackLimit) > -30 " +
            " [[AND WorkFormNO=#{tel.myTwfNO}]] " +
            " [[AND SDeptName =#{tel.sdeptName}]]")
    List<Map<String, Object>> notHandleTelJson_gxq(@Param("sbdeptId") String deptId, @Param("tel") TwfSendBackEty twfSendBackEty);

    /**
     * 导出未处理电话工单数据
     * @param deptId 办理部门
     * @return
     */
    @Select(" SELECT t1.PkId pkId,t1.WfId,t2.FmContent,t1.GetDealPK AS telId,t2.WorkFormNO," +
            " t2.WsTopic FromTopic,t2.FromName,t2.FromTelA FromTel," +
            " '12345' SpareString,t3.FmAddress,t3.FromTime,t3.DFmClaName,SBDeptName,BackDesc," +
            " (select SortName from bSort where CodePk=left(t3.DCntACode,4)) dCntAName1, " +
            " (select SortName from bSort where CodePk=left(t3.DCntACode,6)) dCntAName2, " +
            " (select SortName from bSort where CodePk=left(t3.DCntACode,8)) dCntAName3, " +
            " t1.GetTime signTime,t1.SDeptName,t1.SeqName,t1.SortName," +
            " t1.DealName,CONVERT(VARCHAR(10),BackLimit,20) AS BackLimit," +
            " BackTime,BackState AS BackState,BackRemark," +
            " case when t1.SendState = 10 then 1 when t1.SendState = 11 then 2 when t1.SendState=40 then 3 when t1.SendState=40 and t1.BackState=21 then 4 when t1.SendState=51 then 5 else -1 end as currentState" +
            " FROM tWfSendBack t1 left join tWorkFormBase t2 on t1.WfId=t2.PkId left join tTelGetDeal t3 on t2.GetDealPK=t3.PkId " +
            " WHERE t1.SBDeptID=#{sbdeptId} AND t1.isDel=0 AND t1.SendState in(10,11,40,51) AND dbo.frTelWFStep(WfId)>399 AND t1.SendTime <= getdate() and t1.SendTime >= dateadd(year,-1,getdate()) ")
    List<NotHandleTelExcel> notHandleTelExport(@Param("sbdeptId") String deptId);

    /**
     * 上级催办电话数据
     * @param deptId 办理部门
     * @param twfSendBackEty 电话派单
     * @return
     */
    @Select(" SELECT t1.PkId,t1.WfId,t2.WorkFormNO AS myTwfNO,t2.WsTopic AS myTwfTopic,t2.FmContent,SeqName,t2.SpareString," +
            " SBDeptName,SortName,DealName,CONVERT(VARCHAR(10),BackLimit,20) bkLimit,SDeptName,SendState,BackState," +
            " CONVERT(VARCHAR(10),SendTime,20) sdDate,SendRemark FROM" +
            " tWfSendBack t1 inner join tWorkFormBase t2 on t1.WfId=t2.PkId" +
            " WHERE t1.isUrge=1 AND t1.SBDeptID=#{sbdeptId} AND t1.isDel=0 AND t1.SendState in (10,21,22,23) and t1.BackState in (0,10,12) AND dbo.frTelWFStep(WfId)>399" +
            " [[AND WorkFormNO=#{tel.myTwfNO}]] " +
            " [[AND SDeptName =#{tel.sdeptName}]]")
    List<Map<String, Object>> supUrgeTelOrderJson(@Param("sbdeptId") String deptId,@Param("tel") TwfSendBackEty twfSendBackEty);

    /**
     * 查询上级催办电话工单数据
     * @param deptId 办理部门
     * @return
     */
    @Select(" SELECT t1.PkId pkId,t1.WfId,t2.FmContent,t1.GetDealPK AS telId,t2.WorkFormNO," +
            " t2.WsTopic FromTopic,t2.FromName,t2.FromTelA FromTel," +
            " '12345' SpareString,t3.FmAddress,t3.FromTime,t3.DFmClaName,SBDeptName,BackDesc," +
            " (select SortName from bSort where CodePk=left(t3.DCntACode,4)) dCntAName1, " +
            " (select SortName from bSort where CodePk=left(t3.DCntACode,6)) dCntAName2, " +
            " (select SortName from bSort where CodePk=left(t3.DCntACode,8)) dCntAName3, " +
            " t1.GetTime signTime,t1.SDeptName,t1.SeqName,t1.SortName," +
            " t1.DealName,CONVERT(VARCHAR(10),BackLimit,20) AS BackLimit," +
            " BackTime,BackState,BackRemark,SendState " +
            " FROM tWfSendBack t1 left join tWorkFormBase t2 on t1.WfId=t2.PkId left join tTelGetDeal t3 on t2.GetDealPK=t3.PkId " +
            " WHERE t1.isUrge=1 AND t1.SBDeptID=#{deptId} AND t1.isDel=0 AND t1.SendState in (10,21,22,23) and t1.BackState in (0,10,12) AND dbo.frTelWFStep(WfId)>399")
    List<SupUrgeTelExcel> supUrgeTelOrderExport(String deptId);

    @Select("SELECT t1.PkId,t1.WfId,t2.WorkFormNO AS myTwfNO,t2.WsTopic AS myTwfTopic,t2.FmContent,SeqName," +
            " SBDeptName,SortName,DealName,CONVERT(VARCHAR(10),BackLimit,20) bkLimit,SDeptName," +
            " CONVERT(VARCHAR(10),SendTime,20) sdDate,SendRemark,SAttachPath,Mark FROM" +
            " tWfSendBack t1 inner join tWorkFormBase t2 on t1.WfId=t2.PkId" +
            " WHERE t1.IsDel=0 AND t2.IsDel=0 AND SBDeptID=#{subDeptId} AND SendState IN(10,11)" +
            " [[AND WorkFormNO=#{tel.myTwfNO}]] " +
            " [[AND SDeptName =#{tel.sdeptName}]]")
    List<Map<String, Object>> subDeptTelDetailJson(@Param("subDeptId") String subDeptId,@Param("tel") TwfSendBackEty twfSendBackEty);

    @Select("SELECT t1.PkId,t1.WfId,t2.WorkFormNO AS myTwfNO,t2.WsTopic AS myTwfTopic,t2.FmContent,SeqName," +
            " SBDeptName,SortName,DealName,CONVERT(VARCHAR(10),BackLimit,20) bkLimit,SDeptName," +
            " CONVERT(VARCHAR(10),SendTime,20) sdDate,SendRemark,SAttachPath,Mark FROM" +
            " tWfSendBack t1 inner join tWorkFormBase t2 on t1.WfId=t2.PkId" +
            " WHERE t1.IsDel=0 AND t2.IsDel=0 AND SBDeptID=#{subDeptId} AND SendState IN(10,11) and DATEDIFF(day, GETDATE(), t1.BackLimit) > -30 " +
            " [[AND WorkFormNO=#{tel.myTwfNO}]] " +
            " [[AND SDeptName =#{tel.sdeptName}]]")
    List<Map<String, Object>> subDeptTelDetailJson_gxq(@Param("subDeptId") String subDeptId,@Param("tel") TwfSendBackEty twfSendBackEty);

    /**
     * 查找待本部门回复的工单数据
     * 高新区
     * @param paramMap 参数
     * @return 工单列表数据
     */
    @Select("WfSendBackSql#muReplyWaitJson_gxq")
    @Lang(GroovyLangDriver.class)
    List<Map<String, Object>> muReplyWaitJson_gxq(Map paramMap);

    /**
     * 查询临期工单数量
     * 高新区
     * @param deptId 部门编号
     * @return 临期工单数量
     */
    @Select("WfsendBackSql#dueWorkOrderCount")
    @Lang(GroovyLangDriver.class)
    int dueWorkOrderCount(String deptId);

    /**
     * 查找审核本级回复的工单总数
     *
     * @param deptId     部门id
     * @return 工单列表数据
     */
    // @Select("select count(1) from tWfSendBack t1 left join tWorkFormBase t2 on t1.WfId = t2.PkId and t1.IsDel = 0 and t2.IsDel = 0 " +
    //         "left join tm_tWfSendBack_temp t3 on t1.PkId = t3.sbId " +
    //         "where t1.SBDeptID=cast(#{sbdeptId} as varchar) and t1.BackState=10 and t3.sbId is null and convert(varchar(10),t1.SendTime,120) > '2023-01-01 00:00:00' ")
    @Select("WfsendBackSql#countMuReplyChkJson")
    @Lang(GroovyLangDriver.class)
    Integer countMuReplyChkJson(Long deptId);

    /**
     * 查找审核本级回复的工单数据
     * @param deptId 部门id
     * @param queryConditionVo 查询实体
     * @return List<Map<String, Object>> map集合
     */
    @Select("select t2.PkId as myPkVal,WfId,OriLevel,SDeptID as fmDept,SBDeptID as sbDept,WorkFormNO as myTwfNO," +
            "WsTopic as myTwfTopic,SeqName,SortName,DealName,SDeptName,convert(varchar(10),BackLimit,20) as bkLimit," +
            "SBDeptName,convert(varchar(10),BackTime,20) as bkDate,BackState as chgBack,t2.PkId as opDeal " +
            "from tm_tWfSendBack_temp t1 " +
            "left join tWfSendBack t2 on t1.sbId = t2.PkId and t2.IsDel = 0 " +
            "left join tWorkFormBase t3 on t2.WfId = t3.PkId and t3.IsDel = 0 " +
            "where t1.userNo=#{userNo} and t2.SBDeptID=#{sbdeptId} and t2.BackState=10 " +
            "[[and t3.WorkFormNO = #{qc.workFormNO}]] [[and t2.SDeptName =#{qc.sdeptName}]] [[and t3.SUserName =#{qc.opUserName}]]")
    List<Map<String, Object>> getMuReplyChkJson(@Param("userNo")Long userNo,@Param("sbdeptId") Long deptId, @Param("qc") QueryConditionVo queryConditionVo);

    /**
     * 查找审核本级回复的工单数据
     * @return List<Map<String, Object>> map集合
     */
    @Select("WfsendBackSql#muReplyChkJsonData")
    @Lang(GroovyLangDriver.class)
    List<Map<String, Object>> muReplyChkJsonData(Map parameter);
    /**
     * 查找本部门已办毕的工单数据
     * @param deptId 部门id
     * @param queryConditionVo 查询参数
     * @return 工单列表数据
     */
    @Select("select PkId as myPkVal,WfId,GetDealPK as telId," +
            "(select WorkFormNO from tWorkFormBase where PkId=WfId) as myTwfNO," +
            "(select WsTopic from tWorkFormBase where PkId=WfId) as myTwfTopic," +
            "(select fmContent from tWorkFormBase where PkId=WfId) as FmContent," +
            "SDeptName,SeqName,SBDeptName,SortName,DealName,convert(varchar(10),BackLimit,20) as bkLimit," +
            "convert(varchar(10),BackTime,20) as bkDate,BackState as chgBack,SendState,BackState,BackRemark from tWfSendBack " +
            "where SBDeptID=#{sbdeptId} and BackState in (11,21) and IsDel=0 " +
            "[[and (select WorkFormNO from tWorkFormBase where PkId=WfId) = #{qc.workFormNO}]] [[and SDeptName =#{qc.sdeptName}]] [[and SUserName =#{qc.opUserName}]]")
    List<Map<String, Object>> muReplyOverJsonData(@Param("sbdeptId") String deptId, @Param("qc") QueryConditionVo queryConditionVo);

    /**
     * 加载(区县)退回的工单T列表数据
     * 高新区
     * @param sdeptId 部门编号
     * @param queryConditionVo 查询参数
     * @return 列表数据
     */
    @Select("select PkId as myPkVal,WfId,GetDealPK as telId," +
            "(select WorkFormNO from tWorkFormBase where PkId=WfId) as myTwfNO," +
            "(select WsTopic from tWorkFormBase where PkId=WfId) as myTwfTopic," +
            "SeqName,SBDeptName,SortName,DealName,convert(varchar(10),BackLimit,20) bkLimit," +
            "SDeptName,convert(varchar(10),SendTime,20) sdDate,convert(varchar(10),GetTime,20) as bkDate,backState," +
            "BackRemark,PkId as opDeal from tWfSendBack where SBDeptID=convert(varchar,#{sdeptId}) and SendState=50 and IsDel=0 " +
            "[[and (select WorkFormNO from tWorkFormBase where PkId=WfId) = #{qc.workFormNO}]] [[and SDeptName =#{qc.sdeptName}]]")
    List<Map<String, Object>> backPeerDeptAuditTJson(@Param("sdeptId") Long sdeptId, @Param("qc") QueryConditionVo queryConditionVo);

    /**
     * 加载(区县)退回的工单T列表数据
     * 高新区
     * @param parameter 参数
     * @return 列表数据
     */
    @Select("WfSendBackSql#backPeerDeptAuditTJson_gxq")
    @Lang(GroovyLangDriver.class)
    List<Map<String, Object>> backPeerDeptAuditTJson_gxq(Map parameter);

    /**
     * 加载上级不同意退回列表数据
     * 高新区
     * @param deptId 部门编号
     * @param queryConditionVo 查询参数
     * @return 列表数据
     */
    @Select("select PkId as myPkVal,WfId,(select WorkFormNO from tWorkFormBase where PkId=WfId) as myTwfNO," +
            "(select WsTopic from tWorkFormBase where PkId=WfId) as myTwfTopic,SeqName,SBDeptName,SortName,DealName," +
            "convert(varchar(10),BackLimit,20) bkLimit,SDeptName,convert(varchar(10),SendTime,20) sdDate,SendRemark,SAttachPath" +
            " from tWfSendBack where SBDeptID=#{sbdeptId} and SendState=60 and dbo.frTelWFStep(WfId)>399 and IsDel=0 " +
            "[[and (select WorkFormNO from tWorkFormBase where PkId=WfId) = #{qc.workFormNO}]] [[and SDeptName =#{qc.sdeptName}]]")
    List<Map<String, Object>> peerDeptNotPassListJson(@Param("sbdeptId") Long deptId, @Param("qc") QueryConditionVo queryConditionVo);

    /**
     * 获取待本级回复的列表
     * @param num 获取数量
     * @param sbdeptId 承办部门
     * @return
     */
    @Select("select top (#{num}) t1.PkId,WfId,OriLevel,SDeptID,SBDeptID,SeqName,SortName,DealName,SDeptName,BackLimit,SBDeptName,BackState " +
            "from tWfSendBack t1 left join tWorkFormBase t2 on t1.WfId = t2.PkId and t1.IsDel = 0 and t2.IsDel = 0 " +
            "left join tm_tWfSendBack_temp t3 on t1.PkId = t3.sbId " +
            "where t1.SBDeptID=#{sbdeptId} and t1.BackState=10 and t3.sbId is null and DATEDIFF(day,GetDate(),t1.BackLimit) > -30 order by SendTime desc ")
    List<TwfSendBackEty> getAWaitPeerReplyList(@Param("num") Integer num, @Param("sbdeptId") String sbdeptId);
}
